﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using pagination;
using BTS.BLL;
using BTS.Model;
using System.Text;
using System.Xml;
using BTS.COMMON;

public partial class blog : System.Web.UI.Page
{
    PageStructure ps = new PageStructure();
    BlogBLL bll = new BlogBLL();
    int pageSize = 20;
    int current = 1;
    protected string keyword = "";
    protected StringBuilder sbmk = new StringBuilder();

    protected void Page_Load(object sender, EventArgs e)
    {
        string kw = Request.QueryString["kw"];
        string sqlwhere = "";
        if (!string.IsNullOrEmpty(kw))
        {
            keyword = kw;
            sqlwhere = " and (charindex('" + kw + "',title) > 0 or charindex('" + kw + "',Introduction) > 0)";
        }

        string mrks = Request.QueryString["mk"];
        if (!string.IsNullOrEmpty(mrks))
        {
            sqlwhere += " and charindex('" + mrks + "',Remarks) > 0 ";
        }

        ps.PageSize = pageSize;
        List<Blog> blogs = bll.GetList(pageSize.ToString(), current.ToString(), "", " order by utime desc", ref ps);
        pc.PageStruct = ps;
        repArticles.DataSource = blogs;
        repArticles.DataBind();

        string marks = BTSConfiguration.GetNodeValueString("MARKS");
        if (!string.IsNullOrEmpty(marks))
        {
            string[] mks = marks.Split(',');
            sbmk.AppendFormat("<li><a href=\"blog.aspx\">全部[" + bll.CountBlogs("") + "]</a></li>");
            foreach (string mk in mks)
            {
                sbmk.AppendFormat("<li><a href=\"blog.aspx?mk=" + mk + "\">" + mk + "[" + bll.CountBlogs("") + "]</a></li>");
            }
        }

    }

    /// <summary>
    /// 标签连接
    /// </summary>
    /// <param name="remark"></param>
    /// <returns></returns>
    protected string GetRemarkLinks(string remark)
    {
        string[] remarks = remark.Split(',');
        StringBuilder sb = new StringBuilder();
        foreach (string rm in remarks)
        {
            if (!string.IsNullOrEmpty(rm))
                sb.AppendFormat("[<a href=\"blog.aspx?mk={0}\">{0}</a>]", rm);
        }
        return sb.ToString();
    }
}